<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" @click="goDetail(item)">
				<view class="item">
					<view class="line">
						<fui-text text="申请时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="车主资料：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.contact+'【'+item.mobile+'】'" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="申请车牌：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.plate_number" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="申请事由：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<view style="width: 500rpx;">
							<fui-text :text="item.remark.入场时间" color="black" :size="28"></fui-text>
							<fui-text text="到" color="black" :size="28" :padding="['0rpx','6rpx']"></fui-text>
							<fui-text :text="item.remark.离开时间" color="black" :size="28"></fui-text>
							<fui-text :text="item.remark.申请事由" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="button">
						<fui-button width="250rpx" height="70rpx" :disabled="disabledButton" text="允许入场" type="success" @click="confirmPlate(item,index,1)"></fui-button>
						<fui-button width="250rpx" height="70rpx" :disabled="disabledButton" text="拒绝入场" type="danger" @click="confirmPlate(item,index,2)"></fui-button>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无申请车辆!" :marginTop="200"></fui-empty>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		data() {
			return {
				baseUrl:baseUrl,
				list:[],
				disabledButton:false
			}
		},
		onLoad(e) {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			confirmPlate:function(item,index,result){
				this.disabledButton=true;
				this.$post('merchant/car/shenhe',{id:item.id,result:result},true,true).then(res=>{
					this.list.splice(index,1);
				}).catch(e=>{
					this.getList();
				});
			},
			getList:function(callback=false){
				this.$get('merchant/car/apply','',true).then(res=>{
					res=res.map(tx=>{
						tx.remark=JSON.parse(tx.remark);
						return tx;
					});
					this.list=res;
					this.disabledButton=false;
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	width: 100%;
	.line{
		display: flex;
		align-items: center;
		width:100%;
		height: 70rpx;	
	}
	.button{
		display: flex;
		justify-content: space-around;
		align-items: center;
		width:100%;
		margin-top: 30rpx;
	}
}
</style>